<?php
namespace Cyfy;

/** 
 * Module class
 *
 * An abstract class, which are all modules derived from.
 * Contains basic methods and attributes.
 *
 * @category cyfy
 * @author Dandelion <dandelion8888@gmail.com>
 * @version 0.1
 */
abstract class Module extends Translatable
{
    /**
     * Path to the module.
     *
     * Path to the module. Must be stored in array('ClassName'=>'path'), beacuse of PHP problems with inheriting. Ends with forward slash, eg. modules/ClassName/
     * @var array
     */
    protected static $path = array();
    
  
 
    /**
     * Administration method.
     *
     * <ul>
     *     <li>If called with param $name, returns method $name, if available.</li>
     *     <li>If method not found, returns FALSE.</li>
     *     <li>If called with no parameter, returns list of available administration options in associative array.</li>
     * </ul>
     * List of administration entries example:
     * <code>
     *    return array(
	 *			"someDummyExample" => array("name" => "Name of the option" , "description" => "Some description", "permission"=> "a permission"),
	 *			"settings" => array("name" => self :: t(400) , "description" => self :: t(410), "permission"=> "administration")
	 *	  );
     * </code>
     *
     * @param string Called method name.
     * @return mixed Callback result or FALSE.
     */
    static public function administration($name = '')
    {
        return false;
    }    
     
    /**
     * Returns list of blocks or HTML content of called block.
     *
     * <ul>
     *     <li>If $name is an empty string, returns a list of available blocks.</li>
     *     <li>If $name is not empty, then it returns content of called block. If the block doesn't exist, returns FALSE.</li>
     * </ul>
     * @param string Name of the block
     * @return mixed Associative array of blocks, HTML content - string, or FALSE.
     *//*
	static public function blocks($name = '')
    {
        return array();
    }*/
    
    /**
     * Sets path for module.
     *
     * Sets path for module. This method should be called when cyfy starts. 
     * @param string Path to the module with \Cyfy\Cyfy :: $modulesDir prefix.
     */
    static function setPath($path)
    {
        $calledClass = get_called_class();
        self :: $path[$calledClass] = \Cyfy\Cyfy ::  $modulesDir . $path . "/";
    }
    
    /**
     * Gets path of a module.
     * @return string
     */
    static function getPath()
    {
        $calledClass = get_called_class();
        return self :: $path[$calledClass];
    }
    
    
    
    /**
     * Sets a class constant.
     *
     * Sets a class constant. If the constant already exists, it's overwritten.
     *
     * @param string Constant name.
     * @param string Constant value.
     * @return bool  True, if insertion was successful.
     */
    static function define($const, $value)
    {
        return \Cyfy\Constants :: define(cropModuleName(get_called_class()), $const, $value);
    }
    
    /**
     * Returns a constant.
     *
     * @param string Constant name.
     * @return mixed Constant value
     */
    static function constant($const)
    {
        return \Cyfy\Constants :: get(cropModuleName(get_called_class()), $const);
    }
}
